package net.wanho.service.impl;

import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Author：汤小洋
 * Date：2024-01-30 13:51
 * Description：<描述>
 */
@Service
public class MyUserDetailsService implements UserDetailsService {

    @Resource
    private BCryptPasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        // 从数据库查询用户
        // SysUser dbUser = userMapper.selectByUsername(username);
        // dbUser.getUsername();
        // dbUser.getPassword();
        // dbUser.getPermissions();

        User  user = new User(
                username,
                passwordEncoder.encode("admin"),
                AuthorityUtils.createAuthorityList("sys:user:list","sys:user:add","sys:user:edit","ROLE_role_admin")
        );

        return user;
    }

}
